/**
 * 
 */
$(document).ready(function() {

/*	Date.prototype.Format = function (fmt) {  
	    var o = {  
	        "M+": this.getMonth() + 1, //月份   
	        "d+": this.getDate(), //日   
	        "H+": this.getHours(), //小时   
	        "m+": this.getMinutes(), //分   
	        "s+": this.getSeconds(), //秒   
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
	        "S": this.getMilliseconds() //毫秒   
	    };  
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
	    for (var k in o)  
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));  
	    return fmt;  
	} 
	
	
	var str = window.location.search;
	var strs = str.split("?")[1].split("&");
	var id = strs[0].split("=")[1];
	var classSum = strs[1].split("=")[1];//商品种类数
	var countSum = strs[2].split("=")[1];//商品总个数
	var priceSum = strs[3].split("=")[1];//商品总价格
	var payment = decodeURI(strs[4].split("=")[1]);//付款方式
	var delivery = decodeURI(strs[5].split("=")[1]);//收货方式
	
	$("#classSum").val(classSum);
	$("#countSum").val(countSum);
	$("#priceSum").val(priceSum);
	$("#date").val(new Date().Format("yyyy/MM/dd HH:mm:ss"));
	$("#payment").val(payment);
	$("#delivery").val(delivery);
	
	if(id != '' && id!= null){
		$.get(
			"order/initOrder",
			{"id":id},
			function(result){
				$("#name").val(result.name);
				$("#address").val(result.address);
				$("#emailNum").val(result.emailnum);
				$("#phone").val(result.phone);
				$("#email").val(result.email);
			}
		)
	}*/
/*	alert("id = "+id+"      classSum = "+classSum+"      countSum="+countSum+"        priceSum="+priceSum+"      payment="
			+payment+"        delivery="+delivery);*/
	
	
	$('#buy').click(function(){
		var fhfs = $("#payment").val();
		var shfs = $("#delivery").val();
		var date = $("#date").val();
		var classSun = $("#classSum").val();
		var countSum = $("#countSum").val();
		var priceSum = $("#priceSum").val();
		//添加订单。
		$.get(
			"order/addOrder",
			//用户id,付款方式
			{"fhfs":fhfs,"shfs":shfs,"date":date,"classSun":classSun,"countSum":countSum, "priceSum":priceSum},
			function(){
				window.location.href="initMyOrder?id="+$(".myTable").attr("id");
			}
		)		
		//window.location.href="initMyOrder?id="+$(".myTable").attr("id");
	});
	
	$('#reset').click(function(){	
		$("#classSum").val("");
		$("#countSum").val("");
		$("#priceSum").val("");
		$("#date").val("");
		$("#payment").val("");
		$("#delivery").val("");
		$("#name").val("");
		$("#address").val("");
		$("#emailNum").val("");
		$("#phone").val("");
		$("#email").val("");
		//window.location.href="initMyOrder?id="+$(".myTable").attr("id");
	});
});